package com.bwie.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.pojo.TbOrder;
import com.bwie.pojo.TbUser;
import com.bwie.service.IUserService;
import com.bwie.service.TbOrderService;
import com.bwie.mapper.TbOrderMapper;
import com.bwie.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author HP
* @description 针对表【tb_order(订单表)】的数据库操作Service实现
* @createDate 2025-04-21 18:48:54
*/
@Service
public class TbOrderServiceImpl extends ServiceImpl<TbOrderMapper, TbOrder>
    implements TbOrderService{
    @Autowired
    TbOrderMapper orderMapper;
    @Autowired
    IUserService userService;
    @Override
    public R getOrderById(Integer id) {
        TbOrder tbOrder = orderMapper.selectById(id);
        if(tbOrder==null){
            return R.ERROR(404,"订单不存在");
        }
        R r = userService.getUserById(tbOrder.getUserId());
        String s = JSON.toJSONString(r.getData());
        TbUser user = JSON.parseObject(s, TbUser.class);
        tbOrder.setUser(user);
        return R.OK(tbOrder);
    }
}




